<cfcomponent displayname="FusecacheRequestManager" hint="This object is for storing Fusecache objects and information on a PER REQUEST basis.">

	<cfproperty name="currentDepth" type="numeric">
	<cfproperty name="objects" type="array">
	
	<cfset variables.instance = {} />
	
	<!--- init() --->
	<cffunction name="init" access="public" output="false" returntype="fusecache.FusecacheRequestManager" hint="Initialize the Fusecache Request Manager.">
		<cfscript>
			this.currentDepth = 0;
			this.objects = ArrayNew(1);
			return this;
		</cfscript>
	</cffunction>
	
	
	<!--- getCurrentDepth() --->
	<cffunction name="getCurrentDepth" access="public" output="false" returntype="numeric" hint="Returns the current depth (nested level inside the fusebox).">
		<cfreturn this.currentDepth />
	</cffunction>
	
	
	<!--- setCurrentDepth() --->
	<cffunction name="setCurrentDepth" access="private" output="false" returntype="void" hint="Sets the current depth.">
		<cfargument name="nNewDepth" type="numeric" required="true" />
		<cfset this.currentDepth = arguments.nNewDepth />
	</cffunction>
	
	
	<!--- incrementDepth() --->
	<cffunction name="incrementDepth" access="private" output="false" returntype="void" hint="Increments the current depth.">
		<cfset var nNewDepth = (getCurrentDepth() + 1) />
		<cfset setCurrentDepth(nNewDepth) />
	</cffunction>
	
	
	<!--- decrementDepth() --->
	<cffunction name="decrementDepth" access="private" output="no" returntype="void" hint="Decremetns the current depth.">
		<cfset var nNewDepth = (getCurrentDepth() - 1) />
		<cfset setCurrentDepth(nNewDepth) />
	</cffunction>
	
	
	<!--- enterFuse() --->
	<cffunction name="enterFuse" access="public" output="false" returntype="void" hint="Method called when a new fuseaction is started. It increments the current depth and places the Fusecache Item object in the appropriate location.">
		<cfargument name="oFusecacheItem" type="fusecache.FusecacheItem" required="true" />
		<cfset ArrayAppend(this.objects,arguments.oFusecacheItem) />
		<cfset incrementDepth() />
	</cffunction>
	
	
	<!--- leaveFuse() --->
	<cffunction name="leaveFuse" access="public" output="false" returntype="void" hint="Method called when leaving a fuseaction. Automatically decrements the current depth and removes the necessary Fusecache Item object.">
		<cfset ArrayDeleteAt(this.objects,getCurrentDepth()) />
		<cfset decrementDepth() />
	</cffunction>
	
	
	<!--- getObjectAtDepth() --->
	<cffunction name="getObjectAtDepth" access="public" output="no" returntype="fusecache.FusecacheItem" hint="Returns the FusecacheItem at the current fuse-subfuse depth.">
		<cfargument name="nDepth" type="numeric" required="false" default="#getCurrentDepth()#" />
		<cfif (ArrayLen(this.objects) GTE arguments.nDepth)>
			<cfreturn this.objects["#arguments.nDepth#"] />
		</cfif>
	</cffunction>

</cfcomponent>